<%-- 
    Document   : RegisterAction
    Created on : Nov 17, 2013, 12:39:17 PM
    Author     : smarzoug
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="ece.fr.edu.fac.utilisateur.oad.ProfilDAO,ece.fr.edu.fac.utilisateur.modele.Profil,ece.fr.edu.fac.controleur.outils.DateAnalysis"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>RegisterAction.jsp</title>
    </head>
    <body>
        <% 
            String target="RegisterForm.jsp?status=Registration Failed"; 
            try{
            Profil rb = new Profil(); 
            rb.setFirstName(request.getParameter("fname")); 
            rb.setLastName(request.getParameter("lname")); 
            rb.setBirthDate(DateAnalysis.parseDate(request.getParameter("bdate")));
            rb.setCity(request.getParameter("city")); 
            rb.setState(request.getParameter("state")); 
            rb.setCountry(request.getParameter("country")); 
            rb.setStatus("pending"); 
            rb.setFirstLogin(0); 
            rb.setLoginID(request.getParameter("loginname")); 
            rb.setLoginType("user"); 
            rb.setPassword(request.getParameter("password")); 
            int questid=0; 
            if(request.getParameter("ch")!=null) 
            { 
                rb.setSecretQuestionID(questid); 
                rb.setOwnSecretQuestion(request.getParameter("ownquest")); 
            } 
            else 
            { 
                questid=Integer.parseInt(request.getParameter("squest")); 
                rb.setSecretQuestionID(questid); 
                rb.setOwnSecretQuestion("Not Mentioned"); 
            } 
            rb.setSecretAnswer(request.getParameter("sanswer")); 
            rb.setLocale(request.getLocale().toString()); 
            boolean flag=new ProfilDAO().registration(rb);

            if(flag) 
               target = "RegisterForm.jsp?status=Registration Success"; 
            else  
                target = "RegisterForm.jsp?status=Registration Failed"; 
                }catch(Exception e){e.printStackTrace();}
            RequestDispatcher rd = request.getRequestDispatcher(target);
            rd.forward(request,response);    
    %>
    </body>
</html>
